/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.common;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.text.TextUtils;
import com.qihoo.b.e;
import com.qihoo.gamecenter.sdk.common.i.c;

public class d {
    private static Object a = new Object();
    private static String b = null;

    public static int a(Context paramContext) {
        return b(paramContext, "QHOPENSDK_APPID");
    }

    public static String b(Context paramContext) {
        return c(paramContext, "QHOPENSDK_APPKEY");
    }

    public static String c(Context paramContext) {
        return c(paramContext, "QHOPENSDK_PRIVATEKEY");
    }

    public static String d(Context paramContext) {
        if (b != null) {
            c.a("AppInfo", new Object[] { "getChannel sAppChannel=", b });
            return b;
        }
        return e(paramContext);
    }

    private static String e(Context paramContext) {
        synchronized (a) {
            if (!(TextUtils.isEmpty(b))) {
                c.a("AppInfo", new Object[] { "getAppChannel sAppChannel=", b });
                return b;
            }
            String str = f(paramContext);
            if ((TextUtils.isEmpty(str)) || (str.startsWith("qch_default")))
                str = "default";
            b = str;
        }
        c.a("AppInfo", new Object[] { "getAppChannel=", b });
        return b;
    }

    private static String f(Context paramContext) {
        Object localObject = g(paramContext);
        c.a("AppInfo", new Object[] { "loadApkChannel=", localObject });
        if (TextUtils.isEmpty((CharSequence) localObject)) {
            String str1 = paramContext.getApplicationInfo().sourceDir;
            if (!(TextUtils.isEmpty(str1))) {
                String str2 = e.a(str1);
                if (!(TextUtils.isEmpty(str2))) {
                    if ((str2.startsWith("err")) && (str2.length() > "err".length()))
                        str2 = "qch_" + "default" + str2.substring("err".length());
                    if (!(TextUtils.isEmpty(str2))) {
                        localObject = str2;
                        a(paramContext, (String) localObject);
                        c.a("AppInfo", new Object[] { "saveApkChannel=", localObject });
                    }
                }
            }
        }
        c.a("AppInfo", new Object[] { "readApkChannel=", localObject });
        return ((String) localObject);
    }

    private static String g(Context paramContext) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("sdk_apk_info", 0);
        return localSharedPreferences.getString("sdk_apk_channel", null);
    }

    private static boolean a(Context paramContext, String paramString) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("sdk_apk_info", 0);
        return localSharedPreferences.edit().putString("sdk_apk_channel", paramString).commit();
    }

    private static int b(Context paramContext, String paramString) {
        Bundle localBundle = h(paramContext);
        return ((localBundle != null) ? localBundle.getInt(paramString) : 0);
    }

    private static String c(Context paramContext, String paramString) {
        Bundle localBundle = h(paramContext);
        Object localObject = (localBundle != null) ? localBundle.getString(paramString) : null;
        return ((localObject != null) ? localObject : "");
    }

    private static Bundle h(Context paramContext) {
        if (paramContext == null)
            return null;
        PackageManager localPackageManager = paramContext.getPackageManager();
        try {
            ApplicationInfo localApplicationInfo = localPackageManager.getApplicationInfo(
                    paramContext.getPackageName(), 128);
            if (localApplicationInfo != null)
                return localApplicationInfo.metaData;
        } catch (PackageManager.NameNotFoundException localNameNotFoundException) {
            c.b("AppInfo", new Object[] { localNameNotFoundException.toString() });
        }
        return null;
    }

    public static String a() {
        return "d165cf6f828c950d2fe".toLowerCase();
    }
}